// 导入获取权限的接口
import { getProfileAPI } from '@/api/user'
import { routes, resetRouter } from '@/router/index'
export default {
  namespaced: true,
  state: {
    // 权限标识
    permission: [],
    // 路由规则
    menuList: []
  },
  mutations: {
    // 修改权限标识
    setPermissions (state, newPermission) {
      state.permission = newPermission
    },
    // 修改路由规则
    setMenuList (state, asyncRoutes) {
      state.menuList = [...routes, ...asyncRoutes]
    },
    // 清空路由规则
    clearMenuList (state) {
      state.menuList = []
      resetRouter()
    }
  },
  actions: {
    async getPermission (store) {
      // 获取用户权限信息
      const { data: res } = await getProfileAPI()
      store.commit('setPermissions', res.permissions)
      return res.permissions
    }
  }
}
